This page just serves as a quick reminder for creating different objects. Creating Objects:
Filled or framed rectangles: FramedRect(x coordinate, y coordinate, width, height, canvas); the default color for filled objects is black
Filled or framed ovals: FramedOval(x coordinate, y coordinate, width, height, canvas);
Lines: Line(starting x coordinate, starting y coordinate, ending x, ending y, canvas);
Text: Text("what you want printed", x, y, canvas);
Filled or framed arcs: FramedArc(x, y, width of circle, height of circle, starting angle in degrees, degrees away from starting angle, canvas);
Setting Colors :
To set a color for an object, first, you have to make a variable for the object that you make.
So, If you want to set color for a FilledRect, first, set a variable for the object that you've made (EX. private FilledRect theName;),
and now, all you have to do is to write the code(EX.theName.setColor(Color.red); ) below the line where you created the object.
Color.black (sets of colors you can use in objectDrawing, or you could use numbers to set colors)
Color.blue
Color.cyan
Color.darkGray
Color.gray
Color.green
Color.lightGray
Color.magenta
Color.orange
Color.pink
Color.red
Color.white
Color.yellow
Along with the colors already inserted into the Java api, you may also create your own colors using RGB format. The RGB(red, green, blue) format consists of three number, each between 0 and 255. Now for an example.
For example purposes, let's call our object "ball". "ball" is a FilledOval, that is the easiest way to have a colored object.
private FilledOval ball;//creates the ball variablepublicvoid begin(){
ball = new FilledOval(0,0,10,10,canvas);//set the new color
ball.setColor(newColor(255, 255, 0));//makes the ball a shade of yellow}
There it is, a custom color is made. It can be really useful when trying to make people, or different shades of laundry*cough*cough*.
There are other methods that are useful for Drawable Objects, such as:
.move(a,b) will move the object in the x-direction a amount, & in the y-direction b amount
.moveTo(x,y)will move the object to an (x,y) location
.hide() will hide the object from view
.show()will show the object
.sendBackward() will send the object behind other objects on the screen
.sendForward()will send the object forward, from behind
.getColor() will return the color of the object
.getWidth()will return the width of the object
.setWidth() will set the width of the object
.getHeight()will return the height of the object
.setHeight() will set the height of the object
.getStart()will return the starting point of the object (mainly for lines, since circles do not have a start)
.getEnd() will return the ending point of the object (mainly for lines, since circles do not have a end)
.getLocation()will return the location of the object
.setEndPoints() will set the end points of an object (lines)
.sendToFront() // will send the object to the front of everything
EXAMPLE of making two objects with "if" statement.
importjava.awt.*;importobjectdraw.*;publicclass ChristmasTree extends FrameWindowController
{publicvoid begin(){
makeUpsideDownTree(200,300,100);
makeSideTree(200, 300, 100);}publicvoid makeTree(int middle, int y , int length){//first thing is a base caseif( length <=0)return;else{//draw the line and recall the methodLine temp =newLine(middle - length/2, y,
middle + length/2, y, canvas);
temp.setColor(Color.green);
makeTree(middle, y-2, length-1);}}publicvoid makeUpsideDownTree(int middle, int y , int length){//first thing is a base caseif( length <=0)return;else{//draw the line and recall the methodLine temp =newLine(middle - length/2, y,
middle + length/2, y, canvas);
temp.setColor(Color.green);
makeUpsideDownTree(middle, y+2, length-1);}}publicvoid makeSideTree(int middle, int y, int length){if(length <=0)return;else{Line temp =newLine(middle, y + length/2,
middle, y - length/2, canvas);
temp.setColor(Color.green);
makeSideTree(middle+2,y, length-1);}}}
Creating Objects :
Filled or framed rectangles: FramedRect(x coordinate, y coordinate, width, height, canvas); the default color for filled objects is black
Filled or framed ovals: FramedOval(x coordinate, y coordinate, width, height, canvas);
Lines: Line(starting x coordinate, starting y coordinate, ending x, ending y, canvas);
Text: Text("what you want printed", x, y, canvas);
Filled or framed arcs: FramedArc(x, y, width of circle, height of circle, starting angle in degrees, degrees away from starting angle, canvas);
Setting Colors :
To set a color for an object, first, you have to make a variable for the object that you make.
So, If you want to set color for a FilledRect, first, set a variable for the object that you've made (EX. private FilledRect theName;),
and now, all you have to do is to write the code(EX. theName.setColor(Color.red); ) below the line where you created the object.
Along with the colors already inserted into the Java api, you may also create your own colors using RGB format. The RGB(red, green, blue) format consists of three number, each between 0 and 255. Now for an example.
For example purposes, let's call our object "ball". "ball" is a FilledOval, that is the easiest way to have a colored object.
There it is, a custom color is made. It can be really useful when trying to make people, or different shades of laundry*cough*cough*.
Example:
There are other methods that are useful for Drawable Objects, such as:
EXAMPLE of making two objects with "if" statement.